#include "system_clock.h"
#include "stdio.h"

namespace bestv{


void initSystemClock(){
	MMRESULT res = timeBeginPeriod(1);
	if(res != TIMERR_NOERROR){
		printf("Erroy by timeBeginPeriod()\n");
	}
}

tickT getTicks(){
	/*
	LARGE_INTEGER	ticks;
	BOOL reg = QueryPerformanceCounter(&ticks);
	if(reg){
		return ticks.QuadPart;
	}else{
		//QueryPerformanceCounter not available
		return btvapiTimeNow();
	}
	*/
	return timeGetTime();
}

tickT getTickFreq(){
	/*
	LARGE_INTEGER frequency;
	BOOL ret = QueryPerformanceFrequency(&frequency);
	if(ret != 0){
		return frequency.QuadPart;
	}
	else{
		return btvapiClocksPerSec();
	}
	*/
	return 1000;
}

tickT doSubtraction(tickT t1, tickT t2){
	tickT TIME_WRAP = 0xffffffff;
	if(t2 < t1)
		return (tickT)(t2 + (TIME_WRAP - t1));
	else
		return (tickT)(t2 - t1);
}



void setThreadAffiniyMaskWrapper(){
	//setThreadAffinityMask();
}

void sleepMilliseconds(btvU32 m){
	//in this particular implementation
	//ticks ar milliseconds
	Sleep(m);
}

void sleepTicks(btvU32 m){
	Sleep(m);
}

}//namespace bestv